import { RouterMount, createRouter } from 'uni-simple-router';
import store from '@/wlkutils/store'
const router = createRouter({
    platform: process.env.VUE_APP_PLATFORM,
    routerErrorEach: ({
                          type,
                          msg
                      }) => {
        console.log({
            type,
            msg
        })
        if (type === 0) {
            router.$lockStatus = false;
        }
    },
    routes: [...ROUTES]
});


//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// 权限控制登录
    if (to.meta && to.meta.auth && !store.getters.isLogin) {
        store.commit("setLoadingShow", false);
        store.commit("setLoginPopupShow", true);
        // console.log('还需要一个全局通用登录页面，后期考虑')
        next(false);
	}else {
		next();
	}
});

// 全局路由后置守卫
router.afterEach((to, from) => {
    // console.log('跳转结束')
})

export {
	router,
	RouterMount
}
